package com.example.eado.expandablerecyclerviewdemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by eado on 2016/3/16.
 */
public class AlertTestAdapter extends ExpandableRecyclerAdapter<AlertTestAdapter.AlertBean2> {

    private static final int TYPE_All = 2;//加载完所有数据了；footview为“已经加载完”
    private static final int TYPE_NONE = 3;//没有数据；

    private static final int TYPE_ITEM1 = 4;//item带图表；
    private static final int TYPE_ITEM2 = 5;//item不带图表；
    private static final int TYPE_ITEM3 = 6;//一多配电房，收起；
    public static final int TYPE_PERSON = 1001;

    public AlertTestAdapter(Context context) {
        super(context);
        setItems(getSampleItems());
    }

    public static class AlertBean2 extends ExpandableRecyclerAdapter.ListItem {
        public String docid;
        public String room_title;
        public String digest;
        public String imgsrc;
        public String source;
        public String ptime;
        public int type;


        public AlertBean2(String docid, String room_title, String digest, String imgsrc, String source, String ptime, int type){
            super(type);
            this.docid = docid;
            this.room_title = room_title;
            this.digest = digest;
            this.imgsrc = imgsrc;
            this.source = source;
            this.ptime = ptime;
            this.type=type;
        }
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ExpandableRecyclerAdapter.ViewHolder vh = null;
        switch (viewType) {
            case TYPE_ITEM1://item带图表；
                vh = new ItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_alert_view, parent, false));
                break;
            case TYPE_ITEM2://item不带图表；
                vh = new ItemViewHolder2(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_alert, parent, false));
                break;
            case TYPE_ITEM3://一多配电房，收起；
                vh = new ItemViewHolder3(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_collapse, parent, false));
                break;
            case TYPE_NONE://
//                view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                vh = new FooterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.footer, null));
                break;
            case TYPE_All://
//                view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                vh = new FooterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.footer, null));
                break;
            default:
//                view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                vh = new FooterViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.footer, null));
                break;
        }
        return vh;
    }

    @Override
    public void onBindViewHolder(ExpandableRecyclerAdapter.ViewHolder holder, int position) {
        switch (getItemViewType(position)) {
            case TYPE_ITEM1:
                ((ItemViewHolder) holder).alertname.setText("一多监测\\P04\\la 过流");
                ((ItemViewHolder) holder).yidu.setText("已读");
                break;
            case TYPE_ITEM2:
                ((ItemViewHolder2) holder).alert_name.setText("共创监测\\P04\\la 过流");
                ((ItemViewHolder2) holder).weidu.setText("未读");
                break;
            case TYPE_ITEM3:
                ((ItemViewHolder3) holder).room_name.setText("一多配电房");
                TextView tv_zhankai = ((ItemViewHolder3) holder).tv_zhankai;
                tv_zhankai.setText("收起");
                ImageView icon_value = ((ItemViewHolder3) holder).icon_value;
                icon_value.setImageResource(R.drawable.collapse);
                break;
            default:
//                ((PersonViewHolder) holder).bind(position);
                break;
        }
    }

    private List<AlertBean2> getSampleItems() {
        List<AlertBean2> data2 = new ArrayList<>();
        data2.add(new AlertBean2("docid" + 6, "room_title" + 6, "digest" +6, "imgsrc" + 6, "source" + 6, "ptime" + 1, 6));
        data2.add(new AlertBean2("docid" + 4, "room_title" + 4, "digest" + 4, "imgsrc" + 4, "source" + 4, "ptime" + 4,  4));
        data2.add(new AlertBean2("docid" + 4, "room_title" + 4, "digest" + 4, "imgsrc" + 4, "source" + 4, "ptime" + 4,  4));
        data2.add(new AlertBean2("docid" + 6, "room_title" + 6, "digest" +6, "imgsrc" + 6, "source" + 6, "ptime" + 1, 6));
        data2.add(new AlertBean2("docid" + 5, "room_title" + 5, "digest" + 5, "imgsrc" + 5, "source" + 5, "ptime" + 5, 5));
        data2.add(new AlertBean2("docid" + 5, "room_title" + 5, "digest" + 5, "imgsrc" + 5, "source" + 5, "ptime" + 5, 5));
        data2.add(new AlertBean2("docid" + 6, "room_title" + 6, "digest" +6, "imgsrc" + 6, "source" + 6, "ptime" + 1, 6));
        data2.add(new AlertBean2("docid" + 5, "room_title" + 5, "digest" + 5, "imgsrc" + 5, "source" + 5, "ptime" + 5, 5));
        data2.add(new AlertBean2("docid" + 5, "room_title" + 5, "digest" + 5, "imgsrc" + 5, "source" + 5, "ptime" + 5, 5));
        return data2;
    }


    /**
     * item带图表；
     */
    public class ItemViewHolder extends ExpandableRecyclerAdapter.ViewHolder {

        public TextView alertname;
        public TextView yidu;
        public ImageView lineChart;

        public ItemViewHolder(View v) {
            super(v);
            alertname = (TextView) v.findViewById(R.id.alert_name);
            yidu = (TextView) v.findViewById(R.id.yidu);
            lineChart = (ImageView) v.findViewById(R.id.linechart);
        }
    }

    /**
     * item不带图表；
     */
    public class ItemViewHolder2 extends ExpandableRecyclerAdapter.ViewHolder {

        public TextView alert_name;
        public TextView weidu;

        public ItemViewHolder2(View v) {
            super(v);
            alert_name = (TextView) v.findViewById(R.id.alert_name);
            weidu = (TextView) v.findViewById(R.id.weidu);
        }
    }

    /**
     * 一多配电房，收起
     */
    public class ItemViewHolder3 extends ExpandableRecyclerAdapter.HeaderViewHolder {

        public TextView room_name;
        public TextView tv_zhankai;
        public ImageView icon_value;//收起；

        public ItemViewHolder3(View v) {
            super(v,(ImageView) v.findViewById(R.id.icon_value),(TextView) v.findViewById(R.id.tv_zhankai));
            room_name = (TextView) v.findViewById(R.id.room_name);
            tv_zhankai = (TextView) v.findViewById(R.id.tv_zhankai);
            icon_value = (ImageView) v.findViewById(R.id.icon_value);
        }
    }

    public class FooterViewHolder extends ExpandableRecyclerAdapter.ViewHolder  {
        public TextView textView;
        public ProgressBar progressBar;

        public FooterViewHolder(View view) {
            super(view);
            textView = (TextView) view.findViewById(R.id.more_data_msg);
            progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
        }
    }
}

